package adapter;

import java.util.List;

import com.wonyesoft.wuliu.R;

import javabeen.CarTypeBeen;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/** 
 * @author  作者 E-mail: 
 * @date 创建时间：2015-6-5 上午11:17:01 
 * @version 1.0 
 * @parameter  
 * @since  
 * @return  
 */
public class CarTypeListAdapter extends BaseAdapter {

	public List<CarTypeBeen> CarType;
	private int xml;
	private Context context;
	private LayoutInflater inflater;
	
	public CarTypeListAdapter(Context context,  List<CarTypeBeen> CarType,
			int xml) {
		this.CarType = CarType;
		this.xml = xml;
		this.context = context;
		if (this.context != null) {
			this.inflater = LayoutInflater.from(context);
		}

	}
	
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return CarType.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return CarType.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		 ViewHolder viewHolder;
		if (convertView == null) {
			convertView = inflater.inflate(xml, null);
			convertView.setBackgroundResource(R.drawable.common_card_background);
			viewHolder = new ViewHolder();
			viewHolder.car_type_imageView=(ImageView) convertView.findViewById(R.id.car_type_imageView);
			viewHolder.cartypename=(TextView) convertView.findViewById(R.id.cartypename);
			
			
			viewHolder.cartypename=(TextView) convertView.findViewById(R.id.cartypename);
			viewHolder.description=(TextView) convertView.findViewById(R.id.description);
			viewHolder.basekm=(TextView) convertView.findViewById(R.id.basekm);
			viewHolder.baseprice=(TextView) convertView.findViewById(R.id.baseprice);
			
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		CarTypeBeen data = CarType.get(position);
		if (data != null) {
			
			if (data.getCartypeid()==1) {
			
				viewHolder.car_type_imageView.setImageResource(R.drawable.car_minimian);
			}
			if (data.getCartypeid()==2) {
				viewHolder.car_type_imageView.setImageResource(R.drawable.car_minimian);
			}
			if (data.getCartypeid()==3) {
				viewHolder.car_type_imageView.setImageResource(R.drawable.car_mian);
			}
			if (data.getCartypeid()==4) {
				viewHolder.car_type_imageView.setImageResource(R.drawable.car_minihuo);
			}
			if (data.getCartypeid()==5) {
				viewHolder.car_type_imageView.setImageResource(R.drawable.car_weihuo);
			}
			if (data.getCartypeid()==6) {
				viewHolder.car_type_imageView.setImageResource(R.drawable.car_huo);
			}
			if (data.getCartypeid()==7) {
				viewHolder.car_type_imageView.setImageResource(R.drawable.common_card_background);
			}
			viewHolder.cartypename.setText(data.getCartypename());// (R.id.myorder_content_flowid);
			viewHolder.description.setText(data.getDescription()); // (R.id.myorder_content_tab);
			viewHolder.basekm.setText(data.getBaseprice()+"元/"+data.getBasekm()+"公里");// (R.id.myorder_content_zhongtext);description
			viewHolder.baseprice.setText("超出:"+data.getOutprice()+"元/"+"每公里"); // (R.id.myorder_content_time);
		
		}

		return convertView;
	}

	class ViewHolder {
		ImageView car_type_imageView;
		TextView cartypename;
		TextView description;
		TextView basekm;
		TextView baseprice;

	}
	
	
}
